/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    map<int, vector<int>> ma;
    vector<vector<int>> levelOrder(Node* root) {
        queue<pair<Node*, int>> que;
        vector<vector<int>> ans;
        if (!root) return ans;
        que.push(pair<Node*, int>(root, 0));
        while (!que.empty())
        {
            pair<Node*, int> temp = que.front();
            que.pop();
            ma[temp.second].push_back(temp.first->val);
            for (auto& x : temp.first->children)
            {
                que.push(pair<Node*, int>(x, temp.second + 1));
            }
        }
        for (auto& x : ma) ans.push_back(x.second);
        return ans;
    }
};